package com.csz.servlet;

import com.csz.bean.Grade;
import com.csz.bean.Student;
import com.csz.service.GradeService;
import com.csz.service.StudentService;
import com.csz.service.impl.GradeServiceImpl;
import com.csz.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(urlPatterns = "/Educational/student/delbyid")
public class delByIdServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接受参数
        String sid = req.getParameter("sid");
        //2.service 操作
        //  2.1 查询年级的：

        //  2.2查询主键的：
        StudentService service = new StudentServiceImpl();
        int i = service.delStu(sid);
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        if(i>0){
            writer.println("<script>alert('删除成功');location.href='/Educational/student/getStudentList'</script>");
        }else{
            writer.println("<script>alert('删除失败');location.href='/Educational/student/getStudentList'</script>");
        }

    }
}
